package group.ocr.Service.Impl;

import group.ocr.Config.ImageConfig;
import group.ocr.Mapper.ImageMapper;
import group.ocr.Service.ImageService;
import group.ocr.Utils.OSSUtils;
import group.ocr.pojo.image;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.List;

@Service
public class ImageServiceImpl implements ImageService {
    @Autowired
    private OSSUtils ossUtils;
    @Autowired
    private ImageMapper imageMapper;
    @Autowired
    private ImageConfig imageConfig;
    @Override
    public String saveImage(MultipartFile image) throws IOException {
        String title=image.getOriginalFilename();
        String font="宋体";
        String author="王羲之";
        String url=ossUtils.upload(image);
        imageMapper.saveImage(title,font,author,url);
        return "上传文件："+title+"\n"+"文件url为："+url;
    }

    @Override
    public void collectImage(int id) {
        image Image=imageMapper.selectById(id);
        imageConfig.addToCollection(Image);
    }

    @Override
    public List<image> selectAllImages() {
        return imageMapper.selectAllImages();
    }
}
